/**
 * 
 */
package com.wubo.sec.core;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * @author wubo
 * @CreateDate 2010-8-5
 * @version 1.0.01
 */
public class SecurityFilter implements Filter {

	public void destroy() {
		
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		try{
			HttpServletRequest req = (HttpServletRequest) request;
			if(HttpServletRequestHolder.getHttpServletRequest() != null){
				HttpServletRequestHolder.remove();
				HttpServletRequestHolder.set(req);
			}else{
				HttpServletRequestHolder.set(req);
			}
			
			if(req.getRequestURI().indexOf("j_spring_security_check") != -1){
				String mark = req.getParameter("mark");
				UserLoginPageHelper.setMark(mark);
			}
			
			chain.doFilter(request, response);
		}finally{
			HttpServletRequestHolder.remove();
			UserLoginPageHelper.clearMark();
		}
	}
	
	public void init(FilterConfig arg0) throws ServletException {
		
	}
}
